package com.fdl.dao.security;

import java.io.Serializable;
import java.util.List;

import com.fdl.dao.base.Dao;
import com.fdl.dao.base.impl.BaseHibernateDao;
import com.fdl.dao.model.security.Role;

/**
 * 角色Dao 
 * @project: hb-intra
 * @Date:2010-8-4
 * @version  1.0
 * @Company: 33e9
 * @author zhangYong.huang
 */
public class RoleDao extends BaseHibernateDao implements Dao {
	private UserDao userDao;

	private static final String hql = "select resc from Role role left join " +
			"role.permissions permi left join permi.resources resc"
			+ " where permi.status='1' and role=?";

	public RoleDao() {
		super(Role.class);
	}

	public Role get(Serializable id) {
		return (Role) super.load(id);
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	/**
	 * 通过role找出其所有合法的resource
	 */
	public List findResourcesByRole(Role role) {

		return getHibernateTemplate().find(hql, role);
	}

}
